

var middle=function(tokens){
  let obj ={};
  let arr =[]
  for(let i=0;i<tokens.length;i++){
    if(Object.hasOwn(obj,tokens[i])){
      obj[tokens[i]]++
    }else{
      obj[tokens[i]]=1
    }
  }
  arr = Object.entries(obj)
  const sortArray =  arr.sort((a,b)=>b[1]-a[1])

  console.log(sortArray)
  const filterArray = sortArray.filter((item,index,arr)=> item[1]===arr[0][1])
  console.log(filterArray)
  const mapArray = filterArray.map((item,index)=>item[0]).sort((a,b)=>a-b)

  var result =0;

  var len = mapArray.length

  if(len%2==0){

    result = ((Number)(mapArray[len/2])+(Number)(mapArray[len/2-1]))/2

  }else{
    result = mapArray[Math.floor(len/2)]
  }

  console.log(result)
}





var arrs = [10,11,10,19,21,17,21,16,21,18,15,10]

middle(arrs);